
//
//  SearchVC.m
//  DataStatistics
//
//  Created by Kang on 15/10/13.
//  Copyright © 2015年 YTYangK. All rights reserved.
//


#import "SearchVC.h"
#import "EquipmenCell.h"

#import "SearchViewModel.h" //搜索ViewModel
// data
#import <CoreData/CoreData.h> // 暂时未使用，打算在后期版本使用
#import "SystemInfoController.h"// 扫描获取到的设备详情
#import "HeadSearchViewAssembly.h"
#import "UIView+RGSize.h"
#import "AppDelegate.h"
#import "GetiPhoneDevice.h"
#import "JPUSH.h"



#define  RECORD_INDEX_PATH   @"recordIndexPath"

@interface SearchVC () <UIPopoverPresentationControllerDelegate, EquipmenCellDelegate,SystemInfoControllerDelegate,NSObject,HeadSearchViewAssemblyDelegete,YLZHoledViewDelegate> {

    // 需要其他控件控制刷新
    MJRefreshNormalHeader* header;
    MJRefreshBackNormalFooter* footer;

    // 请求字典
    NSDictionary* parameterDic;
    // 点击状态 ， yse -点击 ， no - 没有
    BOOL isDetermineClick;
    //保存数 历史数量
    NSString * recordChoiceDevice;
    //保存选择的设备ID
    NSInteger  recordChoiceDeviceInt;
    // 传给日志列表的未读数量
    int recordChoiceUnread;
    // 搜索字符串值
    NSString * searchTextVlue;
    // 搜索头部 Nav
    HeadSearchViewAssembly *titleView;
    // 教程是否可以全局点击  YES = 是， NO = 不是；
    BOOL isMaskLayerGlobalClick;
}

/** 第三方封装方法 */
//@property (strong, nonatomic) DeploySDK *deploySDK;
/** 透明覆盖背景 */
@property (strong, nonatomic) UIView* maskView;
/** 接收本地语言标识 */
@property (strong, nonatomic) NSString *localStr;
/** 没显示数据时的图片 */
@property (strong, nonatomic) UIButton *notDataBtn;
/** 列表页数 */
@property (assign, nonatomic) int                        page;
/**  判断列表状态 （YES - 刷新状态， NO - 加载状态） */
@property (assign, nonatomic) BOOL                       isToSearchUpdate;

@end

@implementation SearchVC
singleton_for_implementation(SearchVC)


#pragma mark - 原生代码
- (void)viewDidLoad {
    [super viewDidLoad];
    [self updateUI];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupUnreadCount) name:MDC_SET_BADGE object:nil]; // 激活时，推送时
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateCell:) name:MDC_NOTIFICATION_NICK object:nil];
    [[UIApplication sharedApplication] addObserver:self forKeyPath:@"applicationIconBadgeNumber" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:@"监控属性值变化"];

//    if (![[GetiPhoneDevice getCurrentDeviceModel] isEqualToString:@"iPhone Simulator"]) {
//        self.deploySDK.sonWindow = self.appDelegate.window;
//        self.deploySDK.tabBarC    = (TabBarC *)self.tabBarController;
//        [self.deploySDK albbBindChannel]; //这个是绑定推送的账号，问题是如果注册失败会重复执行
//    }
    

    [[JPUSH sharedJPUSH] albbBindChannel]; //这个是绑定推送的账号

    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    
}


#pragma mark - Table view UI and Data
- (void)updateUI {
    _isSearchJumpLiet     =   NO;
     isDetermineClick       =   NO;      //状态标识 -是否点击了某行？
    _isToSearchUpdate     =   YES;
    self.clickFinished        =   YES;
  //  isMaskLayerGlobalClick = NO;
    // 搜索
    self.page = 1;
    searchTextVlue = @"";
    self.searchTableView.backgroundColor = RGB(33, 38, 44, 1);
    self.searchTableView.tableFooterView=   [[UIView alloc]init];//隐藏多余的分割线
   
    //初始化组件
    [self initTableViewMJRefresh];
    // 搜索头部
    [self setupMiddleNavigationItem];
    
    
    
}
- (void)setupMiddleNavigationItem {
    /**  初始化 Nav UI */
    titleView = [[HeadSearchViewAssembly alloc] initWithWithViewController:self];
    titleView.delegete = self;
     UIBarButtonItem *btn   = [titleView rithtScanBtn];
    self.navigationItem.titleView = titleView;
    self.navigationItem.rightBarButtonItem = btn;
    
}
- (void)initTableViewMJRefresh {
    /**
     *  上下拉刷新控件初始化
     */
    header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.isToSearchUpdate = YES;
        self.page = 1;
        [self requestURLwithViewForpage:self.page];
    }];
    
    header.automaticallyChangeAlpha = YES;
    header.lastUpdatedTimeLabel.hidden = YES;
    self.searchTableView.header = header;
    [header beginRefreshing];
    
    footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        self.isToSearchUpdate = NO;
        self.page++;
        [self requestURLwithViewForpage:self.page];
        
    }];
    self.searchTableView.footer = footer;
}
- (void)requestURLwithViewForpage:(int)page {
    /**
      * 请求方法
      */
    NSString * str  =  ([searchTextVlue rangeOfString:@"搜索"].location != NSNotFound) ? @"" : searchTextVlue ;
    NSNumber* num = [NSNumber numberWithInt:page];
    parameterDic = @{ @"current_page" : num,
                                      @"key" : str
                                  };
    [SearchViewModel requestWithUrlForSearchIn:self andParam:parameterDic success:^(EquipmenModel *model) {
        [SearchViewModel sharedSearchViewModel].unreadCount = model.unreadAllCount;
        [self.searchTableView.header endRefreshing];
        [self.searchTableView.footer endRefreshing];
        
        if (self.isToSearchUpdate) { // 更新
             [self.notDataBtn removeFromSuperview];
            if ([model.EListModel count] <= 0) {
                _searchModelAry = nil;
                [self.searchTableView reloadData];
                [self.searchTableView addSubview:[self notDataBtn]];
               // nil = 0
                if ( [[NSUD objectForKey:MDC_SET_SEARCHSTATS] intValue] == 0) {
                    [NSUD setObject:@"加遮" forKey:MDC_SET_MASKVIEW];
                    [self removeMaskLayer];
                    [self addCourseListOfDimensionalCodeScanning];
                }
               
                // 如果没有数据
            }else {
                
                [[NSUD objectForKey:MDC_SET_MASKVIEW] isEqualToString:@"加遮"] ? [self removeMaskLayer] : nil;  //-- 清除罩
                ([[NSUD  objectForKey:MDC_SET_MASKDATAVIEW] intValue] != 0 ) ? [self addCourseListOfFlatStatus] : nil;
                [self setUpQuickSearch:model.EListModel];
                self.navigationController.tabBarItem.badgeValue = [SearchViewModel sharedSearchViewModel].unreadCount;
                [UIApplication sharedApplication].applicationIconBadgeNumber = [SearchViewModel sharedSearchViewModel].unreadCount.intValue;
            }
            self.clickFinished  = true;
            
        }else { // 加载
            
            if ([model.EListModel count] == 0) {
                [self.searchTableView.footer endRefreshingWithNoMoreData];
            }else {
                [self setUpQuickSearch:model.EListModel];
            }
     }

    } failure:^(NSString *error) {
        //_searchModelAry = nil;
        _searchModelAry == nil ? [self.searchTableView addSubview:[self notDataBtn]] : [self.notDataBtn removeFromSuperview];
        (_searchModelAry.count == 0) ? [self removeMaskLayer] : nil;
        //???: 如果为nil 时？应该怎么解决？
        NSLog(@"%@",[NSUD objectForKey:MDC_SET_MASKVIEW]);
        if ([[NSUD objectForKey:MDC_SET_MASKVIEW] isEqualToString:@"加遮"]) {
         [NSUD setObject:@"加遮-2" forKey:MDC_SET_MASKVIEW];
        }
        [self.searchTableView.header endRefreshing];
        [self.searchTableView.footer endRefreshing];
        if(![error isEqualToString:@"数据错误"]) {
             [MBProgressHUD yty_showErrorWithTitle:nil detailsText:error toView:nil];
        }
    }];
    
}
- (void)setUpQuickSearch:(NSArray *)Ary {
    /**
     *  返回数据处理
     */
    if (self.isToSearchUpdate) {
        NSMutableArray* mutaAry = [[NSMutableArray alloc] init];
        [mutaAry addObjectsFromArray:Ary];
        _searchModelAry         = mutaAry;
        [self.searchTableView reloadData];
    }
    else {
        NSMutableArray* mutaAry = [[NSMutableArray alloc] init];
        [mutaAry addObjectsFromArray:_searchModelAry];
        [mutaAry addObjectsFromArray:Ary];
        _searchModelAry         = mutaAry;
        [self.searchTableView reloadData];
    }
}


#pragma mark - YLZHoledView Delegate
- (void)holedView:(YLZHoledView *)holedView didSelectHoleAtIndex:(NSUInteger)index {
    if (index == 0) {
        if (holedView.tag == 120) {
            [self.holdedView removeFromSuperview];
            [titleView showQRCode:nil];
        }else if(holedView.tag == 121) {
            [self addCourseListOfEfficiencyStatus];
        }else if (holedView.tag == 122) {
            [self addCourseListOfGoTOSetPage];
        }else if (holedView.tag == 123){
            [self removeMaskLayer];
            self.navigationController.tabBarController.selectedIndex = 1;
        }
    }
    
    
    if (isMaskLayerGlobalClick) {
        isMaskLayerGlobalClick = NO;
         [self addCourseListOfEfficiencyStatus];
    }
}


#pragma mark - TableView Delegate
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath {
    UITableViewCell* cellheight = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cellheight.frame.size.height;
}
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath*)indexPath {
    
    isDetermineClick = YES;
    if (isDetermineClick == YES) {
        EListModel* list = _searchModelAry[indexPath.row];
        recordChoiceDevice = list.device_id;
        recordChoiceDeviceInt = indexPath.row;
        recordChoiceUnread = list.unread;
        
        [self subtractUnreadCount:list.unread];
        [list setValue:@0 forKey:@"unread"];
        [NSUD setObject:list.nickname forKey:MDC_NICK_NMAE];
        
        // 数组 替换的下标  ， 替换赋予的内容
        [_searchModelAry replaceObjectAtIndex:indexPath.row withObject:list];
        // 更新 cell
        NSIndexPath* indexPaths = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];
        [self.searchTableView reloadRowsAtIndexPaths:@[ indexPaths ] withRowAnimation:UITableViewRowAnimationNone];
        isDetermineClick = NO;
        
        UIBarButtonItem * item = [[UIBarButtonItem alloc] init];
        item.title = NSLocalizedString(@"back", nil);
        self.navigationItem.backBarButtonItem = item;
        
       // [SearchViewModel jumpListDetailWithListModel:_searchModelAry[indexPath.row] forViewController:self];
        [self performSegueWithIdentifier:@"jumpJournalList"  sender:self];
        //获取当前设备名
        [NSUD setObject:list.device_id forKey:@"device_name"];
    }
}


#pragma mark -  TableView DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger row = _searchModelAry.count;
    return row;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
    static NSString* stat = @"EquipmenCell";
    EquipmenCell* cell = (EquipmenCell*)[tableView dequeueReusableCellWithIdentifier:stat];
    if (!cell) {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"EquipmenCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        [tableView registerNib:[UINib nibWithNibName:@"EquipmenCell" bundle:nil] forCellReuseIdentifier:stat];
        cell.delegate = self;
        
    }
    
    EListModel* newlist = _searchModelAry[indexPath.row];
    [cell judgeBtnVlue:newlist.unread isDetermineClick:isDetermineClick];
    [cell setvalueWithList:_searchModelAry[indexPath.row]];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//取消点击效果
    
    return cell;
}


// 这里可以指定那一条是否可以编辑
- (BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath {
    return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath {
    return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
      if (editingStyle == UITableViewCellEditingStyleDelete) {
                    //数据请求
         NSDictionary* dic = @{ @"devices" : [_searchModelAry[indexPath.row] device_id] };
          
          [SearchViewModel requestWithUrlForDeviceRemoveBinding:self andParam:dic success:^(RemoveBindingModel *model) {
                        // 清nil
                        if (_searchModelAry.count <= 1) {
                            self.navigationController.tabBarItem.badgeValue = nil;
                        }
                        EListModel * lis = _searchModelAry[indexPath.row];
                       // 获取推送总数
                        NSString* status =  [NSString stringWithFormat:@"%ld", (long)[UIApplication sharedApplication].applicationIconBadgeNumber];                         int  i = status.intValue - lis.unread;
                        [UIApplication sharedApplication].applicationIconBadgeNumber = i;
                       //删除数据源   _searchModelAry.mutableCopy，如果_searchModelAry,是可变的 再来用mutableCopy 会导致数据无法删除
                        [_searchModelAry removeObjectAtIndex:indexPath.row];
                        [self.searchTableView deleteRowsAtIndexPaths:@[ indexPath ] withRowAnimation:UITableViewRowAnimationLeft]; //删除自己tavleView 的数据
                        [header beginRefreshing];
                        
                    } failure:^(NSString *error) {
                        [MBProgressHUD yty_showErrorWithTitle:nil detailsText:error toView:nil];
                    }];
            }
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {  //滑动时修改文字
    return @"删除";
}

#pragma  mark - HeardSearch Delegate
//FIXME: 这里需要重新考虑
- (void)headSearchDeviceForKeyWord:(UITextField *)textView {
    /**
     *  头部搜索
     */
    searchTextVlue = textView.text;
    [header beginRefreshing];
}


#pragma mark - SystemInfoController Delegate
- (void)dismissViewControllerWithDeviceVlue:(NSString *)Str {
     /** 二维码扫描详情页面设备代理 */
    //  [self requestCityData]; //请求地区数据
    NSMutableDictionary* mutDic = [[NSMutableDictionary alloc] init];
    [mutDic setObject:@"" forKey:@"nickname"];
    [mutDic setObject:@"" forKey:@"unread"];
    [mutDic setObject:@"" forKey:@"ic_money"];
    [mutDic setObject:Str forKey:@"device_id"];
    [mutDic setObject:@"" forKey:@"device_name"];
    [mutDic setObject:@"" forKey:@"state"];
    EListModel* equModel = [EListModel mj_objectWithKeyValues:mutDic];
    
    NSArray* sideBarAry = @[ equModel ];
    
    _searchModelAry = [_searchModelAry arrayByAddingObject:sideBarAry[0]].mutableCopy;
    if (_searchModelAry == nil) {
        _searchModelAry = [[NSMutableArray alloc] initWithObjects:sideBarAry[0], nil];
    }
    NSIndexPath* inPath = [NSIndexPath indexPathForRow:[_searchModelAry count] - 1 inSection:0]; //修改后是： 0 - 原来是 ：self.searchTableView.indexPathForSelectedRow.section
    
    NSLog(@"打印： %@--->%lu-+-->%ld", inPath, (unsigned long)inPath.length, (long)inPath.section);
    [self.searchTableView insertRowsAtIndexPaths:@[ inPath ] withRowAnimation:UITableViewRowAnimationLeft]; //插入的位置数组，后面参数是动画
    [header beginRefreshing];
    
    //前往设置页面
    if ([[NSUD objectForKey:MDC_SET_MASKVIEW] isEqualToString:@"加遮"]) {
        if (![NSUD objectForKey:MDC_SET_MASKDATAVIEW]) {
             [NSUD  setBool:YES forKey:MDC_SET_MASKDATAVIEW]; //设置重新安装了 并且没有数据时，一定要跑一次
            // self.navigationController.tabBarController.selectedIndex = 1;
            [self removeMaskLayer];
            [self addCourseListOfFlatStatus];
           //特殊设置目的是为了让客户点击全局页面跳转下一步
        }
        [NSUD setObject:@"加遮-1" forKey:MDC_SET_MASKVIEW];
    }
}
- (void)onTopBackDown:(id)obj {
    /**
     *  教程未结束时，返回到二维码扫描页面？
     */
    [self removeMaskLayer];
    [self addCourseListOfDimensionalCodeScanning];
}


#define mark - Other
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
    /**
     * 监控数值变化 - 监控对象是 applicationIconBadgeNumber
     */
    NSInteger integer  = [UIApplication sharedApplication].applicationIconBadgeNumber;
    NSLog(@"----->%ld",(long)integer);
    if ([keyPath isEqualToString:@"applicationIconBadgeNumber"]) {
        if (integer <=0) {
            self.navigationController.tabBarItem.badgeValue = nil;
        }else {
            //???: 崩溃了~o(≧口≦)o
            self.navigationController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%ld",(long)integer];
        }
    }
    NSLog(@"%@---->%@---->%@--->%@",keyPath,object,change,context);
}
- (void)setupUnreadCount {
    /**
     *  全局更新的内容
     */
    
    NSString *str = [SearchViewModel sharedSearchViewModel].unreadCount;
    if (str.intValue<= 0 ) {
        [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    }
    
    [header beginRefreshing]; // 刷新列表
}
- (void)updateCell:(NSNotification *)not {
    /**
     *  一条Cell 更新,该方法暂时用于修改昵称时进行改变
     */
    
    EListModel* list = _searchModelAry[recordChoiceDeviceInt];
    [list setValue:[NSUD objectForKey:MDC_NICK_NMAE] forKey:@"nickname"];
    
    NSIndexPath *indexPat =  [NSIndexPath indexPathForRow:recordChoiceDeviceInt inSection:0];
    [self.searchTableView reloadRowsAtIndexPaths:@[ indexPat ] withRowAnimation:UITableViewRowAnimationNone];
}

- (void)subtractUnreadCount:(int)count {
    /**
     *  清除未读信息 - 计数
     */
    int resultCount = 0;
    int numberBadge = [[NSUD objectForKey:@"applicationIconBadgeNumber"] intValue];   // icon 总数
    int tabBadgeValue  = [self.navigationController.tabBarItem.badgeValue intValue];       // tabBadge 总数
    int ecvm_unreadCount = [[SearchViewModel sharedSearchViewModel].unreadCount intValue]; // 后台总数
    
//TODO: 如果icon 数量异常
    // 被减数 是否为 0 或者小于零
    if (count > 0) {
        // 判断tab 有数量不
        if (tabBadgeValue >= 0) {
            if (numberBadge >= 0) {
                resultCount = tabBadgeValue - count;
            }else {
                resultCount = 0;
            }
        }
        
        // 判断计算的变量 coun 值
        if (resultCount <= 0) {
            self.navigationController.tabBarItem.badgeValue = nil;
            [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
        }
        else {
            self.navigationController.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", resultCount];
            [UIApplication sharedApplication].applicationIconBadgeNumber = resultCount;
            [NSUD setObject:@(resultCount) forKey:@"applicationIconBadgeNumber"];
        }
        
        [SearchViewModel sharedSearchViewModel].unreadCount = [NSString stringWithFormat:@"%d", resultCount];
    }
    else {
        
        if (ecvm_unreadCount> 0) {
            [UIApplication sharedApplication].applicationIconBadgeNumber = ecvm_unreadCount;
            [NSUD setObject:@(ecvm_unreadCount) forKey:@"applicationIconBadgeNumber"];
        }else {
            //  小于等于0
            [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
            [NSUD setObject:@(0) forKey:@"applicationIconBadgeNumber"];
        }
    }
}

- (void)addUnreadCount:(id)vlue {
    /**
     *  前台通知来时计算未读信息
     */
    NSDictionary  *dic = (NSDictionary *)vlue;
    NSString *deviceCodeStr = [vlue  objectForKey:@"device_id"];
    
    int inde = 0;
    for (EListModel* obj in _searchModelAry) {
        NSLog(@"%d - - ->%@",inde,obj.device_id);
        if ([deviceCodeStr isEqualToString:obj.device_id]) {
            EListModel* list = _searchModelAry[inde];
            NSString *status = [dic objectForKey:@"unread"];
            [list setValue:[NSNumber numberWithInt:status.intValue] forKey:@"unread"];
            
            
            NSIndexPath *indexPat =  [NSIndexPath indexPathForRow:inde inSection:0];
            [self.searchTableView reloadRowsAtIndexPaths:@[ indexPat ] withRowAnimation:UITableViewRowAnimationNone];
            break;
        }
        inde++;
    }
    
}
- (void)JumpWithVlue:(id)vlue {
    /**
     *  根据数据 - 跳转页面
     */
    NSDictionary  *dic = vlue;
    NSLog(@"%@",dic);
    
    int inde = 0;
    for (EListModel* obj in _searchModelAry) {
        NSLog(@"%d - - ->%@",inde,obj.device_id);
        if ([[vlue objectForKey:@"device_id"] isEqualToString:obj.device_id]) {
            
            EListModel* list = _searchModelAry[inde];
            recordChoiceDevice = list.device_id;   // 后台- 单条数
            recordChoiceDeviceInt = inde;
            recordChoiceUnread = list.unread;
            [self subtractUnreadCount:list.unread];
            [list setValue:@0 forKey:@"unread"];
            [NSUD setObject:list.nickname forKey:MDC_NICK_NMAE];//objectForKey:
            NSIndexPath *indexPat =  [NSIndexPath indexPathForRow:inde inSection:0];
            [self.searchTableView reloadRowsAtIndexPaths:@[ indexPat ] withRowAnimation:UITableViewRowAnimationNone];
          //  [SearchViewModel jumpListDetailWithListModel:_searchModelAry[inde] forViewController:self];
            [self performSegueWithIdentifier:@"jumpJournalList"  sender:self];
            //获取当前设备名
            [NSUD setObject:list.device_id forKey:@"device_name"];
            break;
        }
        inde++;
    }
    
}


/**
 *  移除新手教程并且设置 nil
 */
- (void)removeMaskLayer {
    // 移除并且设置 nil
    [self.holdedView removeFromSuperview];
    self.holdedView = nil;
}

/**
 *  教程-二维码扫描引导
 */
- (void)addCourseListOfDimensionalCodeScanning {
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH -190, 94, 150, 30)];
    [label setTextColor:[UIColor whiteColor]];
    [label setFont:[UIFont systemFontOfSize:15]];
    [label setText:@"扫描二维码绑定设备"];
    
    UIImageView *sketchMapImage = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2 -150, SCREEN_HEIGHT/2 - 100, 300, 200)];
    sketchMapImage.image = [UIImage imageNamed:@"SketchMap"];
    [self addMaskLayerRect:CGRectMake(SCREEN_WIDTH- 45, 22, 40, 40) fingerPoint:CGPointMake(SCREEN_WIDTH - 65, 76) setTag:120 andImage:[UIImage imageNamed:@"image_1"] imageAry:@[[UIImage imageNamed:@"image_2"],[UIImage imageNamed:@"image_1"]] addSubview:@[label,sketchMapImage]];
}

/**
 *  教程-设备列表平板状态引导
 *  （安装APP时才出现引导，只显示一次效果，如果一开始账号有数据，不弹出）
 */
- (void)addCourseListOfFlatStatus {
    if (self.holdedView == nil) {
    isMaskLayerGlobalClick = YES;
        
    CGSize MDC_size = CGSizeMake(45, 45);
    CGPoint MDC_point = CGPointMake(12, 80);
    CGPoint MDC_fingerPoint = CGPointMake(80, 130);

    UIImageView * image = [[UIImageView alloc] initWithFrame:CGRectMake(MDC_point.x +5, MDC_point.y+MDC_size.height +5, 240, 400)];
    [image setImage:[UIImage imageNamed:@"设备列表断开-连接"]];

    CGRect rect = {MDC_point, MDC_size};
    [self addMaskLayerRect:rect fingerPoint:MDC_fingerPoint setTag:121 andImage:[UIImage imageNamed:@"shouzhi1"]  imageAry:@[[UIImage imageNamed:@"shouzhi1"],[UIImage imageNamed:@"shouzhi2"]]  addSubview:@[image]];
    }
}
/**
 *  教程-设备列表效率状态引导
 */
- (void)addCourseListOfEfficiencyStatus {
    [self removeMaskLayer];
    CGSize MDC_size = CGSizeMake(65, 65);
    CGFloat pointFloat;
    if (SCREEN_WIDTH == 320) {
        pointFloat = SCREEN_WIDTH - 75.f;
    }else if(SCREEN_WIDTH == 375) {
        pointFloat = SCREEN_WIDTH - 85.f;
    }else if (SCREEN_WIDTH == 414) {
        pointFloat = SCREEN_WIDTH - 83.f;
    }
    
    CGPoint MDC_point = CGPointMake(pointFloat, 71);
    CGPoint MDC_fingerPoint = CGPointMake(MDC_point.x - 20, 130) ;
    CGRect rect = {MDC_point, MDC_size};
    UIImageView *efficiencyStatusImage = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2 - 110, 145, 220, 342)];
    [efficiencyStatusImage setImage:[UIImage imageNamed:@"efficiencyImage"]];
    
    [self addMaskLayerRect:rect fingerPoint:MDC_fingerPoint setTag:122 andImage:[UIImage imageNamed:@"image_1"] imageAry:@[[UIImage imageNamed:@"image_1"],[UIImage imageNamed:@"image_2"]] addSubview:@[efficiencyStatusImage]];
    
}
/**
 *  教程-设置引导
 */
- (void)addCourseListOfGoTOSetPage {
    [self removeMaskLayer];
    CGFloat w =      (SCREEN_WIDTH > 320) ? (SCREEN_WIDTH -195): SCREEN_WIDTH -185;
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(w, SCREEN_HEIGHT - 90, 150, 30)];
    [label setTextColor:[UIColor whiteColor]];
    [label setFont:[UIFont systemFontOfSize:15]];
    [label setText:@"相关设置"];
    
  //  [UIView animateWithDuration:0.32 animations:^{
        CGFloat x  =      (SCREEN_WIDTH > 320) ? 261: 220;
        [self addMaskLayerRect:CGRectMake(x, SCREEN_HEIGHT - 40, 40, 40) fingerPoint:CGPointMake(x ,SCREEN_HEIGHT - 62 ) setTag:123 andImage:[UIImage imageNamed:@"image_3"]  imageAry:@[[UIImage imageNamed:@"image_3"],[UIImage imageNamed:@"image_4"]]  addSubview:@[label]];
  //  }];
    
}



- (void)addMaskLayerRect:(CGRect)rect  fingerPoint:(CGPoint)point setTag:(NSInteger)tag andImage:(UIImage *)image imageAry:(NSArray <UIImage *> *)ary  addSubview:(NSArray <UIView *> *)views {
 // 为了不重复写这代码，就抽出来的 遮罩层
    if (self.holdedView == nil) {
        CGRect MDC_rect = rect;
        self.holdedView =[UtilToolsClss teturnMaskViewForObj:self maskLayerRect:MDC_rect fingerPoint:point setTag:tag layerRadius:30 andImage:image imageAry:ary];
        
        if (views != nil) {
            for(UIView *sonView in views) { [self.holdedView addSubview:sonView];}
        }
        [[UIApplication sharedApplication].keyWindow addSubview:self.holdedView];
        
    }
}


#pragma mark - Segues
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier compare:@"jumpJournalList"] == NO) {
        id vc = segue.destinationViewController;
        [vc setValue:recordChoiceDevice  forKey:@"journalDeviceCode"]; //设备编号
        [vc setValue:@(recordChoiceUnread) forKey:@"journalUnread"]; //未读条数
    }
}



#pragma mark -  getter
- (UIButton *)notDataBtn {
    if (!_notDataBtn) {
        _notDataBtn = [UtilToolsClss  noDataBtn:NSLocalizedString(@"No Results", @"没有设备")];
    }
    return _notDataBtn;
}
- (NSString *)localStr {
    if (!_localStr) {
        _localStr = [NSString stringWithFormat:@"%d",[UtilToolsClss judgeLocalLanguage]];
    }
    return _localStr;
}
//- (DeploySDK *)deploySDK {
//    return [DeploySDK sharedDeploySDK];
//}
- (AppDelegate*) appDelegate {
    return (AppDelegate*)[[UIApplication sharedApplication] delegate];
}



@end
